function exist(variable,i){
	return variable != null;
}
function empty(variable){
	return !exist(variable) || variable === '';
}
function truthy(variable){
	return exist(variable) && x !== false;
}
function params(){
	var url = tl_config.his_url;
	var start =url.indexOf('?')+1;
	var params = url.substring(start);
	var parr = [];
	var paramMap = {
	};
	parr = params.split('&');
	for(var i in parr){
		var key=parr[i].substring(parr[i].indexOf('='),0);
		paramMap[key]=parr[i].substring(parr[i].indexOf('=')+1);
	}
	return paramMap;
}
function mapIfExist(fun,datas){
	if(exist(datas)){
		_.map(datas,fun);
	}
}
function loadProvince(id){
	areaParentChange(id,1);
}
function areaParentChange(id,parentId,remove){
	jQuery.ajax({
		type : 'GET',
		contentType : 'application/json',
		async : false,
		data : {
			parentId : parentId,
			token:token
		},
		url : server_url+'/areaManager/getByParent.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			console.log(data);
			if (data.retCode == "0000") {
				jQuery("#"+id).find("option").remove();
				if(exist(remove)){
					jQuery("#"+remove).find("option").remove();
				}
				mapIfExist(function(province){
					jQuery("<option value="+province.areaId+">"+province.areaName+"</option>").appendTo("#"+id);
				},data.data);
			} else{
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});
}
//input 为输入框，path为保存路径,fun为完成时回调函数
function ajaxfileuploadUtils(input,path,fun,i){
		console.log("input file change");
		var id = jQuery(input).attr("id");
		jQuery.ajaxFileUpload({
			url : server_url+'rest/fileUpload/uploadPic.do?&ran='+Math.random()+"&id="+jQuery(input).attr("id")+"&filepath="+path,
			type : 'post',
			contentType:"application/json",
			secureuri : false,  
			fileElementId:id,
			data:[jQuery(input).val()],
			complete : function(orignal) {
				var reg = /<pre.*?>(.*?)<\/pre>/;
				var json = reg.exec(orignal["responseText"]);
				var data = eval("("+json[1]+")");
				if(exist(fun)){
					fun(data,input,i);
				}else{
					defaultAjaxCallBack(data,id);
				}
				/*jQuery("#"+id).live("change",function(){
					ajaxfileuploadUtil(jQuery("#"+id), path);
				});*/
			},
			error: function(e) { 
				console.log(e);
				/*jQuery("#"+id).live("change",function(){
					ajaxfileuploadUtil(jQuery("#"+id), path);
				});*/
			} 
		});
		
}
function defaultAjaxCallBack(data,id){
	console.log(data);
	if (data.retCode = "0000") {
		var path= data.data;
		jQuery("#"+id).siblings("input[type=hidden]").val(path);
		jQuery("#"+id).siblings("img").attr("src",path);
		
	}else{
		easyDialog.open({
			container:{
				header:"温馨提示",
				content:'上传失败'
			},
			noFn : true							
		});
	}
}
